#tkinter_radiobutton.py
#coding=utf-8
import tkinter
def radioselect():
    value = "你选择的选项值为：" + str(var.get())
    label.config(text = value)

#创建顶层窗口
topwin = tkinter.Tk()
#初始化窗口大小
topwin.geometry('250x120')  
#设置窗口标题
topwin.title('单选按钮测试')

var = tkinter.IntVar() 
var.set(2)  #默认选中值为2这一项
r1 = tkinter.Radiobutton(topwin, text="李白", variable=var, 
                         value=1, command=radioselect)
r1.pack(anchor = tkinter.W )

r2 = tkinter.Radiobutton(topwin, text="杜甫", variable=var, 
                         value=2, command=radioselect)
r2.pack(anchor = tkinter.W )

r3 = tkinter.Radiobutton(topwin, text="白居易", variable=var, 
                         value=3, command=radioselect)
r3.pack(anchor = tkinter.W)

label = tkinter.Label(topwin)
label.pack(anchor = tkinter.W)
radioselect() #调用函数，让Label控件显示单选按钮默认选中的信息。

#进入主循环
topwin.mainloop()